//
//  YMPurchaseRecordVC.swift
//  NewVersionDemo
//
//  Created by zeng on 2018/3/19.
//  Copyright © 2018年 youmy. All rights reserved.
//  我的购买记录

import UIKit

class YMPurchaseRecordVC: UIViewController {
    
    // MARK:- 懒加载属性
    fileprivate lazy var pageTitleView : YMPageTitleView = {[weak self] in
        let titleFrame = CGRect(x: 0, y: 20, width: ym_screen_width, height: 44)
        let titles = ["进行中", "已完成", "已取消"]
        let titleView = YMPageTitleView(frame: titleFrame, titles: titles)
        titleView.delegate = self
        return titleView
        }()
    
    fileprivate lazy var pageContentView : YMPageContentView = {[weak self] in
        
        // 1.确定内容的frame
        let contentFrame = CGRect(x: 0, y: 64, width: ym_screen_width, height: ym_screen_height - 64)
        
        // 2.确定所有的子控制器
        var childVcs = [UIViewController]()
        childVcs.append(YMDuringPurchaseVC())
        childVcs.append(YMPurchaseFinishedVC())
        childVcs.append(YMPushaseCancelVC())
        
        let contentView = YMPageContentView(frame: contentFrame, childVcs: childVcs, parentViewController: self)
        contentView.delegate = self
        return contentView
        }()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.addSubview(pageTitleView)
        self.view.addSubview(pageContentView)
    }

    
}


// MARK: - YMPageTitleViewDelegate
extension YMPurchaseRecordVC: YMPageTitleViewDelegate{
    func classTitleView(_ titleView: YMPageTitleView, selectedIndex index: Int) {
        pageContentView.setCurrentIndex(index)
    }
}

// MARK: - YMPageContentViewDelegate
extension YMPurchaseRecordVC: YMPageContentViewDelegate{
    func pageContentView(_ contentView: YMPageContentView, progress: CGFloat, sourceIndex: Int, targetIndex: Int) {
        pageTitleView.setTitleWithProgress(progress, sourceIndex: sourceIndex, targetIndex: targetIndex)
    }
}
